<template>
  <!-- 详情页，除自制与幕后外 -->
  <div class="more-lists">
    <h3>{{name}}<span class="iconfont icon-zuojiantou" @click="$router.go(-1)"></span></h3>
    <van-list v-model="loading" :finished="finished" finished-text="- End -" @load="onLoad" :error.sync="error"
      error-text="请求失败，点击重新加载">
      <div class="imgs-lists" v-if="more.length">
        <template v-for="ele in more">
          <div class="push-img" v-for="item in ele" :key="item.postid" @click="item.post_type==3?toSpecial(item.postid):ShowPopup([true,item.postid])">
            <img v-lazy="item.image" alt="" />
            <div class="lists-title" v-if="tab!=='album'">
              <p>
                <span>{{ item.cates[0].catename }}</span>&nbsp;&nbsp;/&nbsp;&nbsp;<span>{{ item.duration | min }}</span>
              </p>
              <div>{{ item.title }}</div>
            </div>
            <div class="lists-titles" v-if="tab=='album'">
              <span>{{ name }}</span>
              <p>{{item.title }}</p>
              <div>{{item.app_fu_title }}</div>
            </div>
          </div>
        </template>
      </div>
    </van-list>
  </div>

</template>

<script>
  import {
    getMore,
    getOrder
  } from "../api/more"
   import {
    mapMutations
  } from "vuex"
  export default {
    name:'More',
    props: ['tab', 'name', 'cateid'],
    data() {
      return {
        more: [],
        loading: false,
        finished: false,
        error: false,
        off: 1, //页码,
      }
    },
    // filters: {
    //   min(val) {
    //     let m = Math.floor(val / 60);
    //     m = m < 10 ? "0" + m : m;
    //     let s = Math.floor(val % 60);
    //     s = s < 10 ? "0" + s : s;
    //     return m + "'" + s + '"';
    //   },
    // },
    watch:{
     name(val){
       console.log("路由数据已变",val);
       this.more=[];
       this.off=1;
        //解决开启路由缓存后页面不随参数而变化，将more与off重置，无数据List初始化后会触发一次 load 事件
     }
    },
    methods: {
      onLoad() {
        // 异步更新数据
        this.dataObtain();
        },
      dataObtain(){
        if (this.cateid) {
          console.log(this.cateid);
          getOrder({
            p: this.off,
            size: 9,
            cateid: this.cateid
          }).then(data => {
            this.more.push(data.data);
            console.log(this.more);
            // 加载状态结束
            this.loading = false;
            // 数据全部加载完成
            this.off++;
            if (data.data.length < 10) {
              this.finished = true;
            }
          }).catch(() => {
            this.error = true;
            this.loading = false;
          });
        } else {
          console.log(this.tab);
          getMore({
            p: this.off,
            size: 9,
            tab: this.tab
          }).then(data => {
            this.more.push(data.data);
            console.log(data.data);
            // 加载状态结束
            this.loading = false;
            // 数据全部加载完成
            this.off++;
            if (data.data.length < 10) {
              this.finished = true;
            }
          }).catch(() => {
            this.loading = false;
            this.error = true;
          });
      }  



      },
      ...mapMutations(['ShowPopup']),
            toSpecial(id){
        console.log("专题文章",id);
        this.$router.push({name:'Special',params:{id:id}})
      }
    },

  }
</script>

<style lang="less" scoped>
  .more-lists {
    padding-top: 58px;
  }

  h3 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
    text-align: center;
    line-height: 58px;
    font-size: 14px;
    color: #fff;
    background-color: #000;

    span {
      position: absolute;
      left: 22px;
    }
  }

  .push-img {
    position: relative;
    height: 236px;

    & img {
      width: 100%;
      height: 100%;
    }

    .lists-title {
      position: absolute;
      bottom: 0;
      left: 0;
      padding: 0 0 16px 10px;
      color: #fff;
      text-align: left;

      p {
        font-size: 14px;
        margin-bottom: 10px;
      }

      div {
        font-size: 16px;
      }
    }

    .lists-titles {
      position: absolute;
      bottom: 0;
      left: 0;
      padding: 0 0 16px 10px;
      color: #fff;
      text-align: left;

      span {
        display: inline-block;
        width: 38px;
        font-size: 12px;
        padding: 8px 0;
        border-bottom: 1px solid #fff;
      }

      p {
        font-size: 14px;
        margin: 10px 0 12px 0;
      }

      div {
        font-size: 12px;
      }
    }
  }
</style>